package com.third.customer.service.data;

import com.third.customer.model.dao.param.AreaParam;
import com.third.customer.service.exception.ThirdBadRequestException;
import lombok.Data;
import org.springframework.util.StringUtils;

/**
 * Created by hehuaichun on 2020/5/22.
 */
@Data
public class AreaReq {

    private String county;

    private String community;

    private int page = 0;

    private int limit = 10;

    public void validateForEdit(){
        if(StringUtils.isEmpty(county) && StringUtils.isEmpty(community)){
            throw new ThirdBadRequestException("县区或小区社区参数不能都为空");
        }
    }

    public AreaParam toParam(Long companyId){
        AreaParam param = new AreaParam();
        param.setCommunity(community);
        param.setCompanyId(companyId);
        param.setCounty(county);
        param.setPage(page);
        param.setLimit(limit);
        return param;
    }
}
